﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace CityLife
{
    public partial class BudgetWindow : ChildWindow
    {
        public BudgetWindow()
        {
            InitializeComponent();
		 
			Transportation.ValueChanged+=new System.Windows.RoutedPropertyChangedEventHandler<double>(Transportation_ValueChanged);
            Education.ValueChanged += new RoutedPropertyChangedEventHandler<double>(Education_ValueChanged);
            Police.ValueChanged += new RoutedPropertyChangedEventHandler<double>(Police_ValueChanged);
            HealthCare.ValueChanged += new RoutedPropertyChangedEventHandler<double>(HealthCare_ValueChanged);



            TransportationVal.Text = MainPage.Heart.City.Budget.Transportation.ToString();
            Transportation.Value = MainPage.Heart.City.Budget.Transportation;

            EducationVal.Text = MainPage.Heart.City.Budget.Education.ToString();
            Education.Value = MainPage.Heart.City.Budget.Education;

            PoliceVal.Text = MainPage.Heart.City.Budget.Police.ToString();
            Police.Value = MainPage.Heart.City.Budget.Police;

            HealthCareVal.Text = MainPage.Heart.City.Budget.HealthCare.ToString();
            HealthCare.Value = MainPage.Heart.City.Budget.HealthCare;

        }

        void HealthCare_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            HealthCareVal.Text = Math.Round(e.NewValue).ToString();
        }

        void Police_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            PoliceVal.Text = Math.Round(e.NewValue).ToString();
        }

        void Education_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            EducationVal.Text = Math.Round(e.NewValue).ToString();
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {

           MainPage.Heart.City.Budget.Transportation = Convert.ToInt32(TransportationVal.Text);
           MainPage.Heart.City.Budget.Police = Convert.ToInt32(PoliceVal.Text);
           MainPage.Heart.City.Budget.Education = Convert.ToInt32(EducationVal.Text);
           MainPage.Heart.City.Budget.HealthCare = Convert.ToInt32(HealthCareVal.Text);


           MainPage.Heart.SetDirty();

            this.DialogResult = true;
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        private void Transportation_ValueChanged(object sender, System.Windows.RoutedPropertyChangedEventArgs<double> e)
        {
        	TransportationVal.Text=Math.Round(e.NewValue).ToString();
        }
    }
}

